package com.goodrain.springbootdemo.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.goodrain.springbootdemo.service.RestfulDemoService;
import com.goodrain.springbootdemo.vo.RestResponse;
import com.goodrain.springbootdemo.vo.User;
import org.apache.catalina.mapper.Mapper;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.io.InputStream;

@RestController
public class RestfulDemoController {

    @Autowired
    public RestfulDemoService restfulDemoService;

    @GetMapping("/get-user")
    public RestResponse<User> GetUser() {
        User user = new User();
        user.setEmail("huangrh@goodrain.com");
        user.setName("goodrain");
        user.setPassword("goodrain");

        RestResponse<User> resp = new RestResponse<>();
        resp.setData(user);
        resp.setMsg("ok");
        resp.setCode("10000");
        resp.setSuccess(0);

        return resp;
    }


    @GetMapping("fetch-user")
    public RestResponse<User> Fetch() throws IOException {
        User user = restfulDemoService.fetchUser();
        RestResponse<User> resp = new RestResponse<>();
        resp.setData(user);
        resp.setMsg("ok");
        resp.setCode("20000");
        resp.setSuccess(0);
        return resp;
    }
}
